#!/bin/bash

ENCRYPT_RESULT_OUTPUT="encrypt_output.res"
DECRYPT_RESULT_OUTPUT="decrypt_output.res"
chunk_size_arr=("512*1024" "1024*1024" "2*1024*1024" "4*1024*1024" "8*1024*1024" "16*1024*1024" "32*1024*1024")
# chunk_size_arr=("512*1024")

rm -f $ENCRYPT_RESULT_OUTPUT $DECRYPT_RESULT_OUTPUT

for chunk_size_str in "${chunk_size_arr[@]}"
do
    chunk_size=$(echo "$chunk_size_str" | bc)
    ./encrypto $chunk_size > tmpfile

    grep "encrypt" tmpfile | awk '{print $(NF-1)}' > temp_file
    sed -i '1d' temp_file
    echo -n "$chunk_size " >> $ENCRYPT_RESULT_OUTPUT
    cat temp_file | awk '{sum+=$1} END {printf "%6f\n", sum/NR}' >> $ENCRYPT_RESULT_OUTPUT

    grep "decrypt" tmpfile | awk '{print $(NF-1)}' > temp_file
    sed -i '1d' temp_file
    echo -n "$chunk_size " >> $DECRYPT_RESULT_OUTPUT
    cat temp_file | awk '{sum+=$1} END {printf "%6f\n", sum/NR}' >> $DECRYPT_RESULT_OUTPUT
done